﻿#region Copyright

// All Material Copyright © 2010 Dynamic Concepts Development Corp., All Rights Reserved.
//      Portions Copyright © 1984-2009 Dynamic Concepts Development Corp., All Rights Reserved.
// For further information please contact: SoftwareSupport@dynconcepts.com
// Dynamic Concepts Development Corp.  311 W 57th St. Suite #422, New York, NY 10019

#endregion

#region Using References

using System;
using System.Windows.Threading;
using DynConDevCorp.OpenArch.SupportLibrary.ApplicationInfrastructure;
using DynConDevCorp.OpenArch.SupportLibrary.ParallelExecution.Events;

#endregion

namespace DynConDevCorp.OpenArch.SupportLibrary.ParallelExecution.Scheduling
{
    internal class ScheduledExecutionEnvironmentThreadedTask : DispatcherObject, IDisposable
    {
        #region Constructors

        internal ScheduledExecutionEnvironmentThreadedTask()
        {
            QueuedLogger.GlobalInstance.Log(QueuedLogger.MessageSeverity.Debug, "ScheduledExecutionEnvironmentThreadedTask - Created !!!!!!!!");
            ScheduledExecutionEnvironment.ScheduledExecutionEnvironmentEvent.Add(new ParallelEventHandler<ScheduledExecutionEnvironmentEventArgs>(EventTarget), "Task");
        }

        #endregion

        #region Public Methods

        public void Dispose()
        {
            if (!m_Disposed)
            {
                m_Disposed = true;
                ScheduledExecutionEnvironment.ScheduledExecutionEnvironmentEvent.Remove(new ParallelEventHandler<ScheduledExecutionEnvironmentEventArgs>(EventTarget));
            }
        }

        #endregion

        #region Private Methods

        private void EventTarget(object sender, ScheduledExecutionEnvironmentEventArgs args)
        {
            QueuedLogger.GlobalInstance.Log(QueuedLogger.MessageSeverity.Debug, "EventTarget() - Executed!!!!");
            if (args != null)
            {
                args.ExecuteAction();
            }
        }

        #endregion

        #region Instance Fields (Mutable)

        private bool m_Disposed;

        #endregion
    }
}